<template>
  <div class="appreciationOrder">
    <!-- 增值服务 -->
    <!-- 搜索部分 -->
    <div class="search">
      <el-input
        v-model="search"
        size="mini"
        placeholder="请输入店铺id/订单号/服务类型"
        clearable
        style="width: 250px"
        @keyup.enter.native="handleSearch"
      ></el-input>
      <el-button
        size="mini"
        type="primary"
        @click="handleSearch"
        style="padding: 8px 20px;margin-left: 10px;border: none;color: #626366;background-color: #f1f1f1"
      >搜索</el-button>
    </div>
    <!-- 订单统计 -->
    <Statistics :totalMoney="totalMoney"></Statistics>
    <!-- 表格部分 -->
    <div class="tableData">
      <el-table style="width: 100%;margin-bottom: 40px" :data="tableData">
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" min-width="90" label="订单号" prop="sv_services_order_code"></el-table-column>
        <el-table-column align="center" min-width="90" label="店铺id" prop="sv_user_id"></el-table-column>
        <el-table-column align="center" width="100" label="代币" prop="sv_unitprice"></el-table-column>
        <el-table-column align="center" width="100" label="数量" prop="sv_number"></el-table-column>
        <el-table-column align="center" width="100" label="合计代币" prop="sv_totalprice"></el-table-column>
        <el-table-column
          align="center"
          min-width="160"
          :formatter="dateFormat"
          label="付款时间"
          prop="sv_payment_date"
        ></el-table-column>
        <el-table-column align="center" min-width="110" label="服务类型" prop="sv_services_name"></el-table-column>
        <el-table-column align="center" label="支付方式" prop="sv_paytype"></el-table-column>
        <el-table-column align="center" label="付款状态">
          <template slot-scope="scope">
            <span
              :style="scope.row.sv_order_state === '已完成' ? 'color: inherit' : 'color: #ff0000'"
            >{{scope.row.sv_order_state}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 这个是分页器 -->
    <Pagination
      :total="total"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    ></Pagination>
  </div>
</template>

<script>
import Statistics from "@/components/Statistics";
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      // 表单数据
      form: {
        business: "",
        status: "",
        payWay: "",
        payTime: ""
      },
      business: [],
      // 表格数据
      tableData: [],
      // 付款状态
      sv_order_state: ["未完成", "已完成"],
      search: "",
      // 总代币
      totalMoney: 0,
      // 分页器的数据
      total: 0, // 总条数
      pageIndex: 1, // 当前页
      pageSize: 10, // 每页数量
      visible: false,
      // 身份令牌
      myToken: ""
    };
  },
  components: {
    Statistics,
    Pagination
  },
  methods: {
    // 初始化函数
    init() {
      // 获取令牌
      this.myToken = sessionStorage.getItem("myToken");
      // 初始化列表
      this.getOrderData();
    },
    // 获取订单列表
    getOrderData() {
      // 发送请求初始化数据
      this.tableData = [
        {
          sv_order_state: -1,
          user_id: "",
          order_id: ""
        }
      ];
      // 发送请求
      this.$api
        .getAppreciationOrderData(
          this.pageIndex,
          this.pageSize,
          this.tableData[0].sv_order_state,
          this.tableData[0].user_id,
          this.tableData[0].order_id,
          this.search.trim(),
          this.myToken
        )
        .then(res => {
          this.totalMoney = 0;
          this.total = res.total;
          if (!res.dataList) {
            this.tableData = res.dataList;
            return;
          }
          this.tableData = res.dataList.map(v => {
            // 没有记录的时间显示为空
            if (v.sv_payment_date.substring(0, 1) == "0") {
              v.sv_payment_date = null;
            }
            // 修改状态
            if (v.sv_order_state == 0) {
              v.sv_order_state = this.sv_order_state[0];
            } else {
              v.sv_order_state = this.sv_order_state[1];
            }
            this.totalMoney += v.sv_unitprice * v.sv_number;
            return {
              ...v,
              sv_services_order_code: v.sv_services_order_code.substring(
                v.sv_services_order_code.length - 8
              )
            };
          });
        });
    },
    // 搜索
    handleSearch() {
      this.pageIndex = 1;
      this.getOrderData();
    },
    //时间格式化
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 分页器的方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrderData();
    }
  },
  mounted() {
    // 初始化函数
    this.init();
  }
};
</script>

<style lang="less" scoped>
@deep: ~">>>";
.appreciationOrder {
  background-color: #fff;
  padding: 20px;
  .search {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }
  // 筛选样式
  .filtrate {
    padding: 5px 10px;
    background-color: #f1f1f1;
    position: relative;
    .el-radio-button {
      margin-right: 10px;
    }
  }
  // 筛选的每一项
  .filtrate @{deep} .el-form-item {
    margin-bottom: 0;
  }
  // 筛选项的标题
  .filtrate @{deep} .el-form-item__label {
    color: #000;
    font-weight: 600;
  }
  // 筛选项的内容
  .filtrate @{deep} .el-radio-button__inner {
    border: 1px solid #f1f1f1;
    background-color: #f1f1f1;
    font-size: 14px;
    color: #626366;
  }
  // 筛选项选中内容
  .filtrate @{deep} .is-active .el-radio-button__inner {
    background-color: #f1f1f1;
    border: 1px solid #439fff;
    box-shadow: unset;
    color: #666;
    border-radius: 4px;
  }
  // 更改表头颜色
  .tableData @{deep} .el-table th {
    background-color: #fafafa;
    color: #252525;
    font-weight: 100;
  }
}
</style>